<?php
include_once dirname(__FILE__).'/config.php';

// Message to be sent
$message = $_GET['message'];

// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';


$message = Array(
	"errorNum" => 0, 
	"message" => "broadcast:notifications", 
	"payload" => $_GET["message"]
);


$fields = array(
	'registration_ids'  => array($_GET['gcmid']),
	'data'              => $message,
);

$headers = array( 
	'Authorization: key=' . GOOGLE_API_KEY,
	'Content-Type: application/json'
);

// Open connection
$ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt( $ch, CURLOPT_URL, $url );

curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode( $fields ) );

// Execute post
$result = curl_exec($ch);

// Close connection
curl_close($ch);

echo $result;

?>
